//
//  XYTabBarController.m
//  OC_weibo
//
//  Created by 李旭阳 on 16/1/5.
//  Copyright © 2016年 apple. All rights reserved.
//

#import "XYTabBarController.h"
#import "XYTabBar.h"
#import "XYHomeViewCtrl.h"
#import "XYNavigationController.h"
#import "XYDiscoverViewCtrl.h"

@interface XYTabBarController ()<XYTabBarDelegate>

@end

@implementation XYTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    //自定义tabbar
    XYTabBar *tabbar = [[XYTabBar alloc] init];
    tabbar.delegate = self;
    [self setValue:tabbar forKeyPath:@"tabBar"];
    
    
    XYHomeViewCtrl *homeCtrl = [[XYHomeViewCtrl alloc] init];
    [self addChildViewController:homeCtrl imageName:@"tabbar_home" title:@"首页"];
    
    UITableViewController *msgCtrl = [UITableViewController new];
    [self addChildViewController:msgCtrl imageName:@"tabbar_message_center" title:@"消息"];

    XYDiscoverViewCtrl *discoverCtrl = [XYDiscoverViewCtrl new];
    [self addChildViewController:discoverCtrl imageName:@"tabbar_discover" title:@"发现"];
    
    UITableViewController *profileCtrl = [UITableViewController new];
    [self addChildViewController:profileCtrl imageName:@"tabbar_profile" title:@"我"];
    
}

#pragma mark 添加tabbar方法
-(void)addChildViewController:(UIViewController *)childCtrl imageName:(NSString *)imageName title:(NSString *)title{
    childCtrl.tabBarItem.image = [[UIImage imageNamed:imageName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    childCtrl.tabBarItem.selectedImage = [[UIImage imageNamed:[NSString stringWithFormat:@"%@_selected",imageName]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    //childCtrl.tabBarItem.title = title;
    //childCtrl.navigationItem.title = title;
    //上面两行代码合并
    childCtrl.title = title;
    
    //设置titleColor
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    dict[NSForegroundColorAttributeName] = [UIColor orangeColor];
    
    [childCtrl.tabBarItem setTitleTextAttributes:dict forState:UIControlStateSelected];
    
    [self addChildViewController:[[XYNavigationController alloc] initWithRootViewController:childCtrl]];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)tabBar:(UITabBar *)tabBar didSelectPlusButton:(UITabBar *)button{
    NSLog(@"加号按钮点击了");
}

@end
